<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    const input = [
        'sz000001',
        'sz000002',
        'sh600001',
        'sh600002',
        'sh600003',
    ];
    const output = {
        sz: ['000001', '000002'],
        sh: ['600001', '600002', '600003'],
    };

    function transform(input) {
        return input
            .map(item => [item.substr(0, 2), item.substr(2, 6)])
            .reduce((prev, [exchange, id]) => {
                if (!prev[exchange]) {
                    prev[exchange] = [id];
                } else {
                    prev[exchange].push(id);
                }
                return prev;
            }, {})
    }
    console.log(transform(input));
    </script>
</body>
</html>